package com.soilflow.web.controller.dahu.web;

import com.soilflow.common.annotation.Log;
import com.soilflow.common.core.controller.BaseController;
import com.soilflow.common.core.domain.AjaxResult;
import com.soilflow.common.core.page.TableDataInfo;
import com.soilflow.common.domain.DahuProcure;
import com.soilflow.common.enums.BusinessType;
import com.soilflow.common.utils.poi.ExcelUtil;
import com.soilflow.info.service.IDahuProcureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 采购Controller
 * 
 * @author party
 * @date 2023-10-27
 */
@RestController
@RequestMapping("/reception/procure")
public class ProcureController extends BaseController {
    @Autowired
    private IDahuProcureService dahuProcureService;

    /**
     * 查询采购列表（只查询当前用户自己的）
     */
//    @PreAuthorize("@ss.hasPermi('system:procure:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(DahuProcure dahuProcure) {
//        startPage();
//        List<DahuProcure> list = dahuProcureService.selectDahuProcureList(dahuProcure);
//        return getDataTable(list);
//    }


    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:procure:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dahuProcureService.selectDahuProcureById(id));
    }

    /**
     * 新增【发布商品求购】
     */
    @PreAuthorize("@ss.hasPermi('system:procure:add')")
    @PostMapping
    public AjaxResult add(@RequestBody DahuProcure dahuProcure) {
        return toAjax(dahuProcureService.insertDahuProcure(dahuProcure));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:procure:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DahuProcure dahuProcure)
    {
        return toAjax(dahuProcureService.updateDahuProcure(dahuProcure));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:procure:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dahuProcureService.deleteDahuProcureByIds(ids));
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:procure:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DahuProcure dahuProcure)
    {
        List<DahuProcure> list = dahuProcureService.selectDahuProcureList(dahuProcure);
        ExcelUtil<DahuProcure> util = new ExcelUtil<DahuProcure>(DahuProcure.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }
}
